package cn.star.jots.actor.service.impl;

import cn.star.jots.actor.mapper.ActorMapper;
import cn.star.jots.actor.pojo.dto.ActorQuery;
import cn.star.jots.actor.pojo.dto.ActorSaveParam;
import cn.star.jots.actor.pojo.entity.Actor;
import cn.star.jots.actor.pojo.vo.ActorVO;
import cn.star.jots.actor.service.ActorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class ActorServiceImpl implements ActorService {

    @Autowired
    ActorMapper actorMapper;

    @Override
    public List<ActorVO> selectAll(ActorQuery actorQuery) {
        log.debug("查询演员,参数:{}", actorQuery);
        return actorMapper.selectAll(actorQuery);
    }

    @Override
    public void save(ActorSaveParam actorSaveParam) {
        Actor actor = new Actor();
        BeanUtils.copyProperties(actorSaveParam, actor);
        if (actorSaveParam.getId() == null) {
            actor.setCreateTime(new Date());
            actorMapper.insert(actor);
        } else {
            actor.setUpdateTime(new Date());
            actorMapper.update(actor);
        }
    }


    @Override
    public void deleteById(Long id) {
        log.debug("删除演员,参数:{}", id);
        actorMapper.deleteById(id);
    }
}
